PureBasic Survival Guide II - Converts
PureBasic Survival Guide
a tutorial for using purebasic for windows 5.70 LTS

Part 0 - TOC
Part I - General
Part II - Converts
Part III - Primer I
Part IV - Primer II
Part V - Advanced
Part VI - 2D Graphics I
Part VII - 2D Graphics II
Part X - Assembly
Part XI - Debugger
Part XII - VirtualBox
Part XIII - Databases
Part XIV - Networking
Part XV - Regular Expressions
Part XVI - Application Data
Part XVII - DPI
Part XXVII - Irregular Expressions
Part XXIX - Projects
 

Part II - Converts
v7.03 26.01.2019

2.1 Converts
2.2 GfaBasic
2.3 PureBasic 4.00
2.4 PureBasic 4.30
2.5 PureBasic 4.40
2.6 PureBasic 4.50
2.7 PureBasic 4.60
2.8 PureBasic 5.11
2.9 PureBasic 5.20
2.10 PureBasic 5.70
2.x Uncovered
 


2.1 Converts
 

This page is dedicated to those coming from another dialect, or older versions.

You can find a (long) list of updates and changes in the PureBasic help file. Scroll to the bottom of the 'contents' tab and click on 'History'.

PureBasic freshmen may want to skip this page and continue with the primer!


2.2 GfaBasic converts
 

This part of the survival guide helps former GfaBasic users to get started with the Windows version of PureBasic.

Why? Because Gfa is no more. Why PureBasic? Because it somewhat resembles GfaBasic. Why convert? Because Gfa is no more, and 32 bit PureBasic makes life a lot easier than old 16 bit GfaBasic for Windows. Why not GfaBasic32? Because it is no more either (and I never liked it anyway).

Why this page? To save you time (and to spare you the troubles others went through).

First have a look at the previous page, if you haven't done so already. Then continue below, where you will find a number of samples and conversions. This is far from complete, more might be added later. Or not... eternally under construction :-)


Variable-types

Variable names follow standard conventions. Variable types are defined using a postfix, except for pointers.
 

' gfabasic

a% = 1
b! = FALSE
c$ = "test"
d% = v:c$  '  pointers are ints

; purebasic

a.l = 1
b.l = 0     ; there's no boolean, but 0 = false, <>0 = true
c$ = "test" ; or c.s = "test"
*d = @c$    ; pointers resemble integers with a different name
 

See also here.
 

Variable scope

Variables in GFA are by default global, in PureBasic they are by default local. See also here.


Procedures

In PureBasic there is no difference between a function and a procedure. Any procedure can return a value. The type of variable returned is defined in the procedure declaration.
 

' gfabasic

procedure test1
  ' do nothing
return

function test2(a%,b%)
  local c%
  c% = a%+b%
  return c%
endfunc

test1
d% = @test2(1,2)
 

; purebasic

Procedure test1()
  ; do nothing
EndProcedure

Procedure.l test2(a.l,b.l)
  c.l = a+b
  ProcedureReturn c
EndProcedure

test1()
d.l = test2(1,2)

See also here.
 

Keywords

Alphabetical list of GfaBasic vs. PureBasic equivalent or alternative keywords / functions.
 

' gfabasic ; purebasic
\ %
^ Pow()
++ +1
char{} PokeS()
do .. loop Repeat .. Forever
exist() FileSize()
function .. return .. endfunc Procedure .. ProcedureReturn .. Endprocedure
getprocaddress() GetFunction()
inkey$ Inkey()
input$(1) no equivalent
instr() FindString()
l: no equivalent
loadlibrary() OpenLibrary()
mod %
not Not
p:() CallFunctionFast()
print PrintN()
procedure .. return Procedure .. EndProcedure
rinstr() no equivalent (see x_rfindstring())
select .. case .. endselect Select .. Case .. Endselect
string$() Lset()
v: @


DLL's

In 16 bit GfaBasic it is necessary to do type forcing / type conversion when making a DLL call. This is not necessary in PureBasic.
 

' gfabasic

ws_winsock_h& = LoadLibrary("WINSOCK.DLL")  '  load the DLL and get back the DLL handle
ws_wsastartup% = GetProcAddress(ws_winsock_h&,"WSAStartup")  '  find the address of the function

...

ws_retval& = P:(ws_wsastartup%)($101,L:V:ws_wsadata.)
 

; purebasic 4.30

ws_winsock_h.i = OpenLibrary(1,"WSOCK32.DLL")  ; load the DLL and get back the DLL handle
*ws_wsastartup = GetFunction(1,"WSAStartup")  ;  find the address of the function

...

ws_retval.i = CallFunctionFast(*ws_wsastartup,$101,@ws_wsadata)
 

See also here and here.


2.3 PureBasic 4.00
 

PureBasic 3.94 was a giant leap forward from older versions. Now v4.00 and all later versions go to infinity and beyond ;-) Yes, as usual they break older code (a PureBasic habit) but what you get in trade is soooo cool, you're definitely going to like it. Here I'll add a few of the more obvious changes...
 

Changes

Some functions have changed in naming or syntax to become more consistent, or have been slightly improved, or are simply outright new. First stuff that changed, by keyword...
 

3.94 4.xx
Inkey() only returns a single character
IsFunction() GetFunction()
Procedure() now supports default values and optional parameters
Protected, Shared, Global, Static now allows assignment of values to variables
ResizeWindow(), MoveWindow() now combined similar to ResizeGadget()
Select Case EndSelect Case now supports ranges
ReadByte(), ReadWord(), ReadString(), etc. specify file number: ReadByte(<nr>) etc.
UseFile() obsolete, file nr now specified in file commands
UseWindow() obsolete, window nr now specified in window commands
WindowWidth(), WindowHeight() WindowWidth(<nr>), WindowHeight(<nr>)

New features
 

arrays and lists have now 'scope' (local or global), are default local and can be used as procedure parameters
global variables and procedure parameters can now have the same names
automatic protection of global variables when used as procedure parameters
strings can now be of any size and may be of an unlimited length
UniCode support with a special new variable type .c (char, used for Unicode independency)
new string variant added: fixed length strings .s{<length>}
additional types 64 bit .q and double float .d
Not is now! we finally got it... so is XOr by the way
Swap does what it says, it swaps two variables of the same type
With / EndWith makes filling structures easier
prototypes and pseudotypes
and more... see the readme.txt file in the PureBasic folder, check the help file, and visit the forum!


2.4 PureBasic 4.30
 

A new version, and new updates! And, as usual, it breaks your existing code :-)

Biggest change is the support of the new integer variable type .i for 32 or 64 bit programs. Just like the size of 'char' .c depends on Unicode mode, so does the size of 'integer' .i depend on the platform the code will be run on. The same applies to pointers!

The x86 32 bits version and x64 64 bits version have two different install packages. You can write cross platform code, but you can't generate it on the same platform.

  • Use Linux to generate Linux programs.
  • Use Windows 32 bits to generate and test 32 bits programs.
  • Use Windows 64 bits to generate and test either 32 bits or 64 bits programs.
Obviously I missed most changes (hehe) but perhaps I'll run into them and mark them with a newer version of PureBasic...
 

Changes.

Some functions have changed in naming or syntax to become more consistent, or have been slightly improved, or are simply outright new. First stuff that changed, by keyword...
 

4.20 4.30
CreateGadgetList() no longer in use, each OpenWindow() now creates its own gadgetlist, you can still use UseGadgetList()
Read you now specify the type of data to be read, as in Read.s Read.l etcetera
StrQ(), ValQ() ... are no longer needed (see the help file)
CountList() ListSize()
lists and arrays as procedure parameters now need additional keywords (not sure if it was 4.30 that changed this though... could be earlier)

New features.
 

.i is a new integer variable that is either 32 or 64 bits depending on the platform
DesktopX() and DesktopY() make multi monitor programming easier


2.5 PureBasic 4.40

Another version, another chance to break things :-)

Many new features showed up in 4.40. Some of the changes below might have been introduced in a previous version, in which case I simply missed them :-)

Changes.
 

4.30 4.40
CallFunctionFast() CallFunctionFast() only accepts integers, preceed strings by the '@' character
FlipBuffer() the synchronization parameter has moved to OpenScreen()
DrawingMode() PureBasic now supports alpha channels
default library subsystem DirectX7 default library subsystem DirectX9

Other.
 

alphachannel support (when things get funny try 24 bit image depth for images and / or icons instead of 32)
new unsigned variable types .a and .u
hash tables aka maps (very cool feature!)
regular expressions
sqlite blobs
projects


2.6 PureBasic 4.50

Shorter release cycle with perhaps fewer features but indeed some important ones! Many bugs seem to be squashed as well.

One of the important changes is the way lower depth images are now handled... all images are now 24 bits (without alpha channel) or 32 bits (with alpha channel), though you can still save them with a lower depth. Also pay attention to the improvements to the debugger...

Changes.
 
 

4.40 4.50
multiple image depths (on Windows only) images are now either 24 or 32 bits!

Other.
 

multiple compilers selectable
purifier tool
improved debugger
data breakpoints

Obviously, and as usual... this doesn't mean there were no other changes, it just means I didn't spot them, used them, of bothered mentioning them :-)


2.7 PureBasic 4.60b1

This upcoming release mostly brings improvements on the 3D side, but there are some other additions and improvements as well.


2.8 PureBasic 5.11

I've skipped a few versions, and the list of changes is humongous! Check the 'history' section in the help file for an overview of all changes. Here are some that caught my attention:
 
 

IP v6
retrieve environmental information such as ComputerName()
line continuation aka multiline (yes!)
wordwrap in the editor gadget
open files in shared mode
new sounds commands like GetSoundPosition()
FreeXXX()
Bool()
improved TypeOf()
updated SQLite and Ogre
better Mac support
many 3D commands
IDE: reformatting code and other improvements
form designer


2.9 PureBasic 5.20

And more changes, mostly related to audio, graphics and joystick. Especially the sprite stuff has been redone. Good stuff for those that want to build a game...


2.10 PureBasic 5.70 LTS

After a long time I'm working again on the survival guide. In the meantime, purebasic 5.70 arrived, and as usual it made some (many!) chances... As I've been paying little attention since 5.11 the list of changes since 5.11 would become rather large... I'll just settle for my major observations... Of course I might simply have overlooked any of these in earlier versions...
 
 

no more support for Ascii mode, we're Unicode only now
session history
Enumerate now supports 'names'

Get ready and start with Primer Part I! 


2.x Uncovered...

This little section is here for my own use, so I can see what I forgot, need to add, or just ignore... Move on, people, nothing to see here :-)
 

A
all sprite3d stuff
alphablend()
a.point = b.point
addwindowtimer()
Ascii()

B
blob
blob

C
cpuname()
customgradient()
clearstructure
cipher libraryCopyList() CopyMap() CopyArray() FreeList() FreeMap() FreeArray()
CopyStructure()
cipher library
CreateFile() unicode support
ClipOutput(), UnclipOutput(), SetOrigin(), GetOriginX(), GetOriginY() 
CPUName(), Un/BindEvent(), Un/BindGadgetEvent(), Un/BindMenuEvent() 

D
DPI aware support for windows apps
DesktopResolutionX(), DesktopResolutionY(), DesktopScaleX(), DesktopScaleY(), DesktopUnscaleX(), DesktopUnscaleY() 
directx11
data
defined() ?
datasection
drawrotatedtext()
datasection
Defined() function
drawalphaimage()
Div ?
DisplayTranslucentSprite() -> replaced with 'Alpha' parameter for DisplayTransparentSprite() 
DisplaySolidSprite() -> replaced with 'Color' parameter for DisplayTransparentSprite() 
DisplayRGBFilter() -> can be replaced with a zoomed sprite with color 
DisplayShadowSprite() -> can be replaced with DisplayTransparentSprite() with color 

E
editorgadget wordwrap
Event()
eventtimer()
finishdatabasequery()
exist() ?
EnumerationBinary
ExamineRegularExpression()

F
fonts
FlushPreferenceBuffers() 
G
GetSoundPosition()
FormatNumber()
gradientcolor() etc.
FlushPreferenceBuffers()
grabdrawingimage()

G
GetUserDirectory()
GadgetWidth/Height()  #PB_Gadget_RequiredSize support
GIF decoder support

H

I
Interface
imageframes (SetImageFrame etc.)
import / importc / endimport
interfaces

J
joystick()
JoystickName(), JoystickZ() 

K

L
lineargradient() etc.
line continuation character _ ?
Literal string escape support using '~'
license files to easy add the needed information when shipping PB programs (see reference documentation)

M
Module
MemoryStringLength()
Mod ?
module support
multicharacter stringfield
monitor coordinates
maps
memorysize()
macro's

N
network library
new IDE shortcuts ^e ^m

O
OpenConsole: an optional 'Mode' parameter for OpenConsole()
OpenScreen() flipmode and refreshrate
on x call y,y,y,y ?
offsetof
outputwidth()

P
postgresqldatabase()
projects
preferences
PlaySound() volume support
PostEvent()

Q

R
Runtime
runtime library ?
removewindowtimer()
RGBA() Alpha()
read
resize window / resize gadget etc. ?
ReverseString()
RoundRect()
regular expressions
ReceiveHTTPMemory()
ReadCharacter unicode support
RunProgram() unicode support
ReadFile() shared read / write
ReadProgramString() format parameter
RefreshDialog()
ReceiveHTTPMemory()
ReceiveHTTPFile()

S
string escape support using ~
StringFingerPrint()
SetRefreshRate()
ShortcutGadget()
StatusBarImage()
ScreenWidth()
sizeof
statusbarprogress()
statusbarimage()
shortcutgadget()
SaveImage() depth parameter
statusbarheight() ?
sgn() ?
SetDatabaseBlob(), SetDatabaseFloat(), SetDatabaseDouble(), SetDatabaseLong() 
StringFingerprint() 
StartFingerprint() NextFingerprint() AddFingerprint() etc.
SpriteOutput() for DX and OpenGL 32 bit support
StartSpecialFX(), StopSpecialFX(), DisplayAlphaSprite(), ChangeAlphaIntensity(), UseBuffer() 

T
toolbar now supports large icons and text
threads
Threaded
threaded
trim ltrim rtrim character
toolbarheight() ?
tar archive support

U
UTF8()

V

W

X

Y

Z
zoomsprite()

#
#PB_File_SharedWrite support to ReadFile() and CreateFile() 
#StringConstant$
#PB_File_SharedRead 
2d drawing modes imageoutput()
.a
.u
^
7z archive creation